package doh.entity;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.*;

@Entity
@Table(name = "PLAYER")
public class Player implements Serializable {
    @Id
    @Column(name = "id")
    private String id;
    @NotNull
    @Column(name = "password")
    private String password;
    @NotNull
    @Column(name = "rating")
    private int rating;
    @NotNull
    @Column(name = "games")
    private int games;
    @NotNull
    @Column(name = "wins")
    private int wins;
    @NotNull
    @Column(name = "wratio")
    private double wratio;
    @NotNull
    @Column(name = "oratio")
    private double oratio;
    @NotNull
    @Column(name = "rocks")
    private int rocks;
    @NotNull
    @Column(name = "papers")
    private int papers;
    @NotNull
    @Column(name = "scissors")
    private int scissors;

    public Player() {
    }

    public Player(
            String id,
            String password,
            int rating,
            int games,
            int wins,
            double wratio,
            double oratio,
            int rocks,
            int papers,
            int scissors) {
        this.id = id;
        this.password = password;
        this.rating = rating;
        this.games = games;
        this.wins = wins;
        this.wratio = wratio;
        this.oratio = oratio;
        this.rocks = rocks;
        this.papers = papers;
        this.scissors = scissors;
    }

    public String get_id() {
        return id;
    }

    public void set_id(String id) {
        this.id = id;
    }

    public String get_password() {
        return password;
    }

    public void set_password(String password) {
        this.password = password;
    }

    public int get_rating() {
        return rating;
    }

    public void set_rating(int rating) {
        this.rating = rating;
    }

    public int get_games() {
        return games;
    }

    public void set_games(int games) {
        this.games = games;
    }

    public int get_wins() {
        return wins;
    }

    public void set_wins(int wins) {
        this.wins = wins;
    }

    public double get_wratio() {
        return wratio;
    }

    public int get_wper() {
        return (int)(wratio*100);
    }

    public void set_wratio(double wratio) {
        this.wratio = wratio;
    }

    public double get_oratio() {
        return oratio;
    }

    public int get_oper() {
        return (int)(oratio*100);
    }

    public void set_oratio(double oratio) {
        this.oratio = oratio;
    }

    public int get_rocks() {
        return (int)((rocks*100)/((double)rocks+papers+scissors));
    }

    public void set_rocks(int rocks) {
        this.rocks = rocks;
    }

    public int get_papers() {
        return (int)((papers*100)/((double)rocks+papers+scissors));
    }

    public void set_papers(int papers) {
        this.papers = papers;
    }

    public int get_scissors() {
        return (int)((scissors*100)/((double)rocks+papers+scissors));
    }

    public void set_scissors(int scissors) {
        this.scissors = scissors;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Player)) {
            return false;
        }
        Player other = (Player) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return id+"\t"+rating+"\t"+"\t"+games+"\t"+wins+"\t"+(int)(wratio*100)+"\t"+(int)(oratio*100)+"\t"+rocks+"\t"+scissors+"\t"+papers;
    }

}
